<template>
  <div class="login">


      <el-input
              type="textarea"
              :rows="10"
              placeholder="请输入或者粘贴表格内容"
              v-model="textInfo">
      </el-input>
      <el-input v-model="ge" placeholder="请输入分隔符，默认为空格"></el-input>
        <p></p>

      <Button @click="handleSubmit" type="primary" long html-type="submit">提交</Button>
      <el-input
              type="textarea"
              :rows="10"
              placeholder="生成的结果"
              v-model="res">
      </el-input>

  </div>
</template>

<script>
  export default {
    name: "tableToMark",
    data() {
      return {
        textInfo: '',
        res: '',
        ge: ''
      };
    },
    mounted() {
    },
    methods: {
        handleSubmit() {
            if(!this.ge){
                console.info("没有输入分隔符，默认为空格",this.ge);
                this.ge = "\t"
            }
            // this.textInfo = "名称\t类型\t样例\t描述\n" +
            //     "name\tstring\tstart\t节点定义唯一编码\n" +
            //     "displayName\tstring\t开始\t节点定义显示名称\n" +
            //     "preInterceptors\tstring\t-\t节点执行前置拦截器\n" +
            //     "postInterceptors\tstring\t-\t节点执行后置拦截器\n" +
            //     "layout\tstring\t20,20,100,50\t布局属性（x,y,w,h）";
            // console.info(this.textInfo)

            //生成的结果
            // | 名称|	类型|	样例|	描述 |
            // | ------------ | ------------ | ------------ | ------------ |
            // | name| 	string| 	leave| 	流程定义唯一编码 |
            // |  displayName| 	string| 	请假流程| 	流程定义显示名称   |
            // |  type| 	string| 	OA审批| 	流程类型 |
            // | instanceUrl| 	string| 	leave_form| 	启动实例要填写的表单key  |
            // |  expireTime| 	string| 	expireTime| 	期待完成时间变量key  |
            // |  instanceNoClass| 	string| 	xx.DefaultNoGenerator| 	实例编号生成器实现类   |
            let rowStr = "|";
            let rows = this.textInfo.split("\n");
            let columnSize = rows[0].split(this.ge).length;
            console.log(1111,this.ge)
            for (let i = 0; i < rows.length; i++) {

                //输出第二行的| ------------ |
                if(i == 1){
                    for (let k = 0; k < columnSize; k++) {
                        rowStr+=" ------------ "+"|";
                    }
                    rowStr+="\n|";
                }


                let cells = rows[i].split(this.ge);
                // let cells = rows[i].split("\t");
                console.info(cells);
                for (let j = 0; j < cells.length; j++) {
                    rowStr+=cells[j]+"|";
                }
                rowStr+="\n|";


            }
            let rs = rowStr.substr(0,rowStr.length-1);
            console.info(rs);
            this.res=rs
        }
    }
  }
</script>

<style scoped>

</style>